//package com.device.operating.controller;
//
//import java.sql.DriverManager;
//import java.sql.PreparedStatement;
//import java.sql.ResultSet;
//import java.sql.SQLException;
//import java.sql.Statement;
//import java.util.ArrayList;
//import java.util.HashMap;
//
//import java.util.List;
//import java.util.Map;
//
//
//import javax.annotation.Resource;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//
//import net.sf.ehcache.Cache;
//import net.sf.ehcache.CacheManager;
//import net.sf.ehcache.Element;
//
//import org.quartz.SchedulerException;
//
//import org.springframework.stereotype.Controller;
//import org.springframework.web.bind.annotation.RequestMapping;
//
//import org.springframework.web.bind.annotation.ResponseBody;
//import org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap;
//import com.device.operating.entity.Cuser;
//import com.device.operating.entity.Olt;
//import com.device.operating.service.BrasService;
//import com.device.operating.service.DeviceService;
//import com.device.operating.service.DslamService;
//import com.device.operating.service.CuserService;
//import com.device.operating.service.DvrelaService;
//import com.device.operating.service.FailureService;
//import com.device.operating.service.FailuretypeService;
//import com.device.operating.service.FieldresService;
//
//import com.device.operating.service.JfService;
//import com.device.operating.service.JxService;
//import com.device.operating.service.JxrelaService;
//import com.device.operating.service.OltService;
//import com.device.operating.service.OnuService;
//import com.device.operating.service.SlaService;
//import com.device.operating.service.SwitchService;
//
//
//@Controller
//public class TpuserController extends BaseController{  
//    CacheManager manager;
//    Cache cache;
//    
//	@Resource(name="OltService")
//	private OltService OltService;
//	
//	@Resource(name="OnuService")
//	private OnuService OnuService;
//	
//	@Resource(name="FailuretypeService")
//	private FailuretypeService FailuretypeService;
//	
//	@Resource(name="FailureService")
//	private FailureService FailureService;
//	
//	@Resource(name="FieldresService")
//	private FieldresService FieldresService;
//	
//	@Resource(name="SwitchService")
//	private SwitchService SwitchService;
//	
//	@Resource(name="BrasService")
//	private BrasService BrasService;
//		
//	@Resource(name="JxService")
//	private JxService JxService;
//	
//	@Resource(name="JxrelaService")
//	private JxrelaService JxrelaService;
//	
//	@Resource(name="JfService")
//	private JfService JfService;
//	
//	@Resource(name="CuserService")
//	private CuserService CuserService;
//	
//	@Resource(name="SlaService")
//	private SlaService SlaService;
//	
//	@Resource(name="DeviceService")
//	private DeviceService DeviceService;
//	
//	@Resource(name="DvrelaService")
//	private DvrelaService DvrelaService;
//	
//	@Resource(name="DslamService")
//	private DslamService DslamService;
//		
//	
////	@RequestMapping("/startusercache")
////	@ResponseBody
////	public Map startusercache(HttpServletRequest request,HttpServletResponse response) throws Exception{
////		Map map=new HashMap<>();
////		if(ifscan()==true){
////			map.put("msg", "缓存已经存在,无法重复启动！");
////			return map;
////		}
////		Map cusermap=new HashMap<>();
////		String url=request.getSession().getServletContext().getRealPath("uploadfile");
////		manager = new CacheManager(url+"/ehcache.xml");		
////		cache = manager.getCache("tpusercache");
////		List<Cuser> listcuser=CuserService.queryall();
////		for(Cuser cuser:listcuser){
////			Element em=new Element(cuser.getCusercode(),cuser.getOltId());
////			cache.put(em);
////		}
////		map.put("msg", "启动成功!");
////		return map;
////	}
//	
//	@RequestMapping("/startusercache")
//	@ResponseBody
//	public Map startusercache(HttpServletRequest request,HttpServletResponse response) throws Exception{
//		Map map=new HashMap<>();
//		if(ifscan()==true){
//			map.put("msg", "缓存已经存在,无法重复启动！");
//			return map;
//		}
//		Map cusermap=new HashMap<>();
//		String url=request.getSession().getServletContext().getRealPath("uploadfile");
//		manager = new CacheManager(url+"/ehcache.xml");		
//		cache = manager.getCache("tpusercache");
//		
//	     java.sql.Connection conn=null;   
//	        Statement stmt=null;		
//			ResultSet rs=null;
//			
//			String url1="jdbc:mysql://133.67.132.122:3306/xasj?useUnicode=true&amp;characterEncoding=utf8";
//			String password="43046721";
//			String user="root";
//	        try{
//	        	Class.forName("com.mysql.jdbc.Driver");
//	        	conn=DriverManager.getConnection(url1,user,password);  
//	        	stmt=conn.createStatement();
//	        	rs=stmt.executeQuery("select username,do_ip,an_onuid,vlan,svlan,an_frame,an_slot,an_port,bas_slot,bas_subslot,bas_port from username_an where access_type like '%DSLAM%' group by username");
//	        	int i=0;
//	        	while(rs.next()){
//	    			Element em=new Element(rs.getString(1),"dslam,"+rs.getString(2)+"| svlan-"+rs.getString("svlan")+
//	    					" vlan-"+rs.getString("vlan")+" ACCESS-"+rs.getString("an_frame")+"/"+rs.getString("an_slot")+
//	    					"/"+rs.getString("an_port")+" BRAS-"+rs.getString("bas_slot")+"/"+rs.getString("bas_subslot")+
//	    					"/"+rs.getString("bas_port")+" onuId-"+rs.getString("an_onuid"));
//	    			cache.put(em);
//	    			System.out.println(++i);
//	        	}
//	        	
//	        	List<Olt> listolt=OltService.queryAll();
//	        	List<String> liststr=new ArrayList<String>();
//	        	int c=1;
//	        	for(Olt olt:listolt){
//	        		String oltId=olt.getOltId();
//	        		liststr.add(oltId);
//	        		String sql="select username,do_ip,an_onuid,vlan,svlan,an_frame,an_slot,an_port,bas_slot,bas_subslot,bas_port from username_an where access_type like '%FTT%' and do_ip in (";
//	        		if(c==80){
//	        			for(String str:liststr){
//	        				sql=sql+"'"+str+"',";
//	        			}
//	        			sql=sql.substring(0,sql.length()-1);
//	        			sql=sql+") group by username";
//	        			rs=stmt.executeQuery(sql);
//			        	while(rs.next()){
//			    			Element em=new Element(rs.getString(1),"olt,"+rs.getString(2)+"| svlan-"+rs.getString("svlan")+
//			    					" vlan-"+rs.getString("vlan")+" ACCESS-"+rs.getString("an_frame")+"/"+rs.getString("an_slot")+
//			    					"/"+rs.getString("an_port")+" BRAS-"+rs.getString("bas_slot")+"/"+rs.getString("bas_subslot")+
//			    					"/"+rs.getString("bas_port")+" onuId-"+rs.getString("an_onuid"));
//			    			cache.put(em);
//			    			System.out.println(++i);
//			        	}
//			        	liststr.clear();
//			        	c=0;
//	        		}
//	        		c++;
//	        	}
//	        }
//	        catch(ClassNotFoundException e1){  
//	            System.out.println("数据库驱动不存在！"+e1.toString());
//	        }  
//	        catch(SQLException e2)  
//	        {  
//	            System.out.println("数据库存在异常"+e2.toString());
//	        }  
//	        finally  
//	        {  
//	            try  
//	            {  
//	                if(rs!=null)  
//	                    rs.close();  
//	                if(stmt!=null)  
//	                    stmt.close();
//	                if(conn!=null)  
//	                    conn.close();
//	            }
//	            catch(SQLException e)  
//	            {  
//	            	e.printStackTrace();
//	            }  
//	        }
//		
////		List<Cuser> listcuser=CuserService.queryall();
////		for(Cuser cuser:listcuser){
////			Element em=new Element(cuser.getCusercode(),cuser.getOltId());
////			cache.put(em);
////		}
//		
//		
//		map.put("msg", "启动成功!");
//		return map;
//	}
//	
//	@RequestMapping("/shutdownusercache")
//	@ResponseBody
//	public Map shutdownusercache(HttpServletResponse response) throws SchedulerException{
//		Map map=new HashMap<>();
//		if(ifscan()==false){
//			map.put("msg", "缓存已是关闭状态,无法重复操作！");
//			return map;
//		}
//		manager.shutdown();
//		map.put("msg", "缓存已停止");
//		return map;
//	}
//	
//	@RequestMapping("/ifusercache")
//	@ResponseBody
//	public Map ifusercache() throws SchedulerException{
//		Map map=new HashMap<>();
//		if(ifscan()==true){
//			map.put("status", true);
//		}else
//			map.put("status", false);
//		return map;
//	}
//	
//	public boolean ifscan() throws SchedulerException{
//		if(manager==null){
//			return false;
//		}
//		String status=manager.getStatus().toString();	
//		if(!status.equals("STATUS_ALIVE")){//未启动
//			return false;
//		}
//		return true;
//	}
//	
//	@RequestMapping("/getcusermap")
//	public String getcusermap(HttpServletRequest request,RedirectAttributesModelMap map){
//		String cusercode=request.getParameter("usercodes");
//		if(cusercode.equals("")){
//			return null;
//		}	
//		String[] cusercodes=cusercode.split(",");
//		StringBuffer sb=new StringBuffer();
//		for(int i=0;i<cusercodes.length;i++){
//			Element ele=cache.get(cusercodes[i]);
//			if(ele==null)
//				continue;
//
////			Cuser cuser=CuserService.querybycusercode(cusercodes[i]);
//			String str=ele.getValue().toString().split(",")[1];
//			String oltId=str.split("\\|")[0];
//			String dvbelong=ele.getValue().toString().split(",")[0];
//			String cuserinfo=cusercodes[i]+"~"+str.split("\\|")[1];
//			int loc=sb.indexOf(oltId);
//			if(loc>0){//包含
//				sb.insert(loc+oltId.length(),","+cuserinfo);
//				continue;
//			}
//			sb.append(dvbelong+","+oltId+","+cuserinfo+":");
//		}
//		String dvIds=sb.toString();
////		map.addFlashAttribute("dvIds", dvIds);
//		if(dvIds.length()!=0){
//			dvIds=dvIds.substring(0, dvIds.length()-1);
//		}else{
//			return "";
//		}
//		map.put("dvIds", dvIds);
//		return "redirect:/creatjxmap";
//	}
//}
